package com.smart.car.points.controller;

import com.alibaba.fastjson.JSONObject;
import com.smart.car.common.res.bean.ResponseResult;
import com.smart.car.common.res.exception.BusinessException;
import com.smart.car.points.entity.PointsExchange;
import com.smart.car.points.service.PointsExchangeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO 积分兑换控制
 * @author: zoutao
 * @date: 2021-01-07
 */
@Slf4j
@RestController
@RequestMapping("exchange")
public class PointsExchangeController {


    @Autowired
    private PointsExchangeService exchangeService;

    /**
     * TODO 新增兑换信息
     * example : {"cardQty":100,"couponCode":"C9527","ctype":0}
     * @param json
     */
    @PostMapping(value = "/create")
    public ResponseResult<Integer> exchange(@RequestBody String json) throws BusinessException {
        log.debug("新增兑换请求： " + json);
        ResponseResult<Integer> result = new ResponseResult<>();
        int rtn = exchangeService.createExchange(json);
        result.setData(rtn);
        return result;
    }

    public static void main(String[] args) {
        PointsExchange exchange = new PointsExchange()
                .setCardQty(100)
                .setCouponCode("C9527")
                .setCtype(0);
        log.info(JSONObject.toJSONString(exchange));
    }
}
